library(pacman)
#p_install_gh("favstats/favstats")
p_load(tidyverse, haven,sjmisc,
forcats, weights, car,
countrycode, lavaan,
semTools, lavaan.survey,
survey, reshape2, favstats,
magrittr, skimr, xray)
range01 <- function(x){(x-min(x, na.rm = T))/(max(x, na.rm = T)-min(x, na.rm = T))}
afro5_url <- url("https://github.com/favstats/database_delib/raw//master/afro5.RData")
afro6_url <- url("https://github.com/favstats/database_delib/raw//master/afro6.RData")
latino2013_url <- url("https://github.com/favstats/database_delib/raw//master/latino2013.RData")
latino2015_url <- url("https://github.com/favstats/database_delib/raw//master/latino2015.RData")
wvs_raw_url <- url("https://github.com/favstats/database_delib/raw//master/wvs_raw.RData")
americas_url <- url("https://github.com/favstats/database_delib/raw//master/americas.RData")
bolivia_url <- url("https://github.com/favstats/database_delib/raw//master/bolivia.RData")
canada_url <- url("https://github.com/favstats/database_delib/raw//master/canada.RData")
asian_raw_url <- url("https://github.com/favstats/database_delib/raw//master/asian_raw.RData")
myanmar_raw_url <- url("https://github.com/favstats/database_delib/raw//master/myanmar_raw.RData")
mongolia_raw_url <- url("https://github.com/favstats/database_delib/raw//master/mongolia_raw.RData")
philip_raw_url <- url("https://github.com/favstats/database_delib/raw//master/philip_raw.RData")
taiwan_raw_url <- url("https://github.com/favstats/database_delib/raw//master/taiwan_raw.RData")
thai_raw_url <- url("https://github.com/favstats/database_delib/raw//master/thai_raw.RData")
malay_raw_url <- url("https://github.com/favstats/database_delib/raw//master/malay_raw.RData")
singapore_raw_url <- url("https://github.com/favstats/database_delib/raw//master/singapore_raw.RData")
sk_raw_url <- url("https://github.com/favstats/database_delib/raw//master/sk_raw.RData")
cambodia_raw_url <- url("https://github.com/favstats/database_delib/raw//master/cambodia_raw.RData")
ESS_raw_url <- url("https://github.com/favstats/database_delib/blob/master/ESS_raw.Rdata?raw=true")
vdems_start_url <- url("https://github.com/favstats/database_delib/raw//master/vdems_start.Rdata")
qog_url <- url("https://github.com/favstats/database_delib/raw//master/qog.Rdata")
load(afro5_url)
delete_na_afro <- function(x) {
x <- Recode(x, "9 = NA;
98 = NA;
99 = NA;
-1 = NA")
return(x)
} # Funktion um die NAs im Afro Datensatz zu bestimmen
# alle Variablen
afro_5 <- afro5 %>%
rename(
educ = Q97, # Variablen umbenennen
income = Q3B,
sex = Q101,
work = Q96,
trust_gov = Q59A,
trust_parliament = Q59B,
trust_police = Q59H,
trust_courts = Q59J,
# demtoday = Q46A
) %>%
mutate_at(
vars(
income, trust_gov, trust_parliament,
trust_police, trust_courts, work
),
delete_na_afro
) %>% # NAs deleten
mutate(
sex = sex - 1, # sex (0/1) codieren
work = Recode(
work, # work (0/1) codieren
"1 = 0;
2 = 1;
3 = 1"
),
age = Recode(
Q1, # missing values l?schen
"-1 = NA;
998 = NA;
999 = NA"
),
# demtoday = Recode(
# demtoday,
# "-1 = NA;
# 98 = NA;
# 99 = NA"
# ),
educ = Recode(
educ,
"-1 = NA;
98 = NA;
99 = NA;
999 = NA"
),
cntry = to_label(COUNTRY_ALPHA),
year = as.numeric(format(DATEINTR, "%Y"))
) %>%
select(
cntry, year, age, sex, income, educ, work,
trust_gov, trust_parliament, trust_police, trust_courts
)
afro_5
save(afro_5, file = "codebooks/singles/afro_5.Rdata")
load(afro6_url)
afro_6 <- afro6 %>%
rename(
educ = Q97,
income = Q4B,
sex = Q101,
work = Q95,
trust_gov = Q52A,
trust_parliament = Q52B,
trust_police = Q52H,
trust_courts = Q52J,
# demtoday = Q40
) %>%
mutate_at(
vars(
income, trust_gov,
trust_parliament, trust_police,
trust_courts, work
),
delete_na_afro
) %>% # NAs deleten
mutate(
sex = sex - 1, # sex (0/1) codieren
work = Recode(
work, # work (0/1) codieren
"1 = 0;
2 = 1;
3 = 1"
),
age = Recode(
Q1, # missing values l?schen
"-1 = NA;
998 = NA;
999 = NA"
),
educ = Recode(
educ,
"-1 = NA;
98 = NA;
99 = NA;
999 = NA"
),
# demtoday = Recode(
# demtoday,
# "8 = NA"
# ),
cntry = to_label(COUNTRY_R5List),
year = as.numeric(format(DATEINTR, "%Y"))
) %>%
# mutate_at(vars(income, educ, age,
# trust_gov, trust_parliament,
# trust_police, trust_courts),
# as.character) %>%
# mutate_at(vars(income, educ, age,
# trust_gov, trust_parliament,
# trust_police, trust_courts),
# as.numeric) %>%
select(
cntry, year, age, sex, income,
educ, work, #demtoday,
trust_gov, trust_parliament,
trust_police, trust_courts
)
afro_6
save(afro_6, file = "codebooks/singles/afro_6.Rdata")
afro_real <- afro_5 %>%
mutate_at(
vars(
income, educ,
trust_gov, trust_parliament,
trust_police, trust_courts
),
range01
)
afro_real2 <- afro_6 %>%
mutate_at(
vars(
income, educ,
trust_gov, trust_parliament,
trust_police, trust_courts
),
range01
)
# length(unique(afro_real$cntry))
# length(unique(afro_real2$cntry))
# table(afro_real2$year)
afro <- rbind(afro_real, afro_real2) %>% as.tbl()
afro
load(latino2013_url)
latino_2013 <- latino2013 %>%
rename(
educ = REEDUC_1,
income = S6,
# demtoday = P50TGB.A,
age = S11
) %>%
mutate(
sex = S10 - 1, # sex variable erstellen
cntry = to_label(IDENPA), # cntry variable erstellen
trust_gov = 5 - P26TGB.B,
trust_parliament = 5 - P26TGB.C,
trust_police = 5 - P28TGB.B,
trust_courts = 5 - P26TGB.E,
year = 2013,
income = 5 - income,
work = Recode(
S19.A,
"2 = 1;
3 = 1;
4 = 0;
5 = 0;
6 = 0;
7 = 0"
)
) %>%
select(
cntry, year, age, sex, income, educ, work,
trust_gov, trust_parliament, trust_police, trust_courts
)
latino_2013
save(latino_2013, file = "codebooks/singles/latino_2013.Rdata")
load(latino2015_url)
latino_2015 <- latino2015 %>%
mutate(sex = S12 - 1) %>% # sex variable erstellen
rename(
educ = REEDUC_1,
income = S4,
# demtoday = P17STGBS,
age = S13
) %>%
mutate(
trust_gov = 5 - P16ST.G,
trust_parliament = 5 - P16ST.F,
trust_police = 5 - P16TGB.B,
trust_courts = 5 - P16ST.H,
work = Recode(
S21.A,
"2 = 1;
3 = 1;
4 = 0;
5 = 0;
6 = 0;
7 = 0"
),
cntry = to_label(IDENPA),
income = 5 - income,
year = 2015
) %>%
select(
cntry, year, age, sex, income, educ, work,
trust_gov, trust_parliament, trust_police, trust_courts
)
latino_2015
save(latino_2015, file = "codebooks/singles/latino_2015.Rdata")
latino_real <- latino_2013 %>%
mutate_at(
vars(
income, educ,
trust_gov, trust_parliament,
trust_police, trust_courts
),
range01
)
latino_real2 <- latino_2015 %>%
mutate_at(
vars(
income, educ,
trust_gov, trust_parliament,
trust_police, trust_courts
),
range01
)
latino <- rbind(latino_real, latino_real2) %>% as.tbl()
latino
load(wvs_raw_url)
wvs <- wvs_raw %>%
rename(
educ = V248,
income = V239,
# demtoday = V141,
age = V242,
year = V262
) %>%
mutate(
sex = V240 - 1, # sex variable erstellen
trust_gov = 5 - V115,
trust_parliament = 5 - V117,
trust_police = 5 - V113,
trust_courts = 5 - V114,
work = Recode(
V229,
"2 = 1;
3 = 1;
4 = 0;
5 = 0;
6 = 0;
7 = 0;
8 = 0"
),
cntry = to_label(V2)
) %>%
select(
cntry, year, age, sex, income, educ, work,
trust_gov, trust_parliament,
trust_police, trust_courts
)
wvs
save(wvs, file = "codebooks/singles/wvs.Rdata")
load(americas_url)
americas_ <- americas %>%
mutate(cntry = to_label(pais)) %>%
select(
cntry, ocup4a, ed, q10new, q1, q2,
b10a, b13, b18, b21a, n3, year
) %>%
rename(
work = ocup4a,
educ = ed,
income = q10new,
sex = q1,
age = q2,
trust_courts = b10a,
trust_parliament = b13,
trust_police = b18,
trust_gov = b21a,
# demtoday = n3
) %>%
mutate(
sex = sex - 1, # sex variable erstellen
work = Recode(
work,
"2 = 1;
3 = 1;
4 = 0;
5 = 0;
6 = 0;
7 = 0"
)
) %>%
select(
cntry, year, age, sex, income, educ, work,
trust_gov, trust_parliament, trust_police, trust_courts
)
americas_
save(americas_, file = "codebooks/singles/americas_.Rdata")
load(bolivia_url)
bolivia_ <- bolivia %>%
mutate(cntry = to_label(pais)) %>%
select(
cntry, ocup4a, ed, q10new, q1, q2,
b10a, b13, b18, b21a, n3, year
) %>%
rename(
work = ocup4a,
educ = ed,
income = q10new,
sex = q1,
age = q2,
trust_courts = b10a,
trust_parliament = b13,
trust_police = b18,
trust_gov = b21a, # viele missing values
# demtoday = n3
) %>%
mutate(
sex = sex - 1, # sex variable erstellen
work = Recode(
work,
"2 = 1;
3 = 1;
4 = 0;
5 = 0;
6 = 0;
7 = 0"
)
) %>%
select(
cntry, year, age, sex, income, educ, work,
trust_gov, trust_parliament, trust_police, trust_courts
)
bolivia_
save(bolivia_, file = "codebooks/singles/bolivia_.Rdata")
load(canada_url)
canada_ <- canada %>%
mutate(cntry = to_label(pais)) %>%
select(
cntry, exc13, education, q10, q1, q2,
b10a, b13, b18, b21a, n3, year
) %>%
rename(
work = exc13,
educ = education,
income = q10,
sex = q1,
age = q2,
trust_courts = b10a,
trust_parliament = b13,
trust_police = b18,
trust_gov = b21a,
# demtoday = n3
) %>%
mutate(
sex = sex - 1, # sex variable erstellen
work = work - 1,
income = ifelse(income == 88, NA, income)
) %>%
select(
cntry, year, age, sex, income, educ, work,
trust_gov, trust_parliament, trust_police, trust_courts
)
canada_
save(canada_, file = "codebooks/singles/canada_.Rdata")
americas <- americas_ %>%
mutate_at(
vars(
income, educ,
trust_gov, trust_parliament,
trust_police, trust_courts
),
range01
)
bolivia <- bolivia_ %>%
mutate_at(
vars(
income, educ,
trust_gov, trust_parliament,
trust_police, trust_courts
),
range01
)
canada <- canada_ %>%
mutate_at(
vars(
income, educ,
trust_gov, trust_parliament,
trust_police, trust_courts
),
range01
)
americas <- rbind(americas, bolivia, canada) %>%
mutate(cntry = as.character(cntry)) %>%
mutate(cntry = ifelse(cntry == "HaitÃ", "Haiti", cntry))
americas
#
# table(americas$cntry)
load(asian_raw_url)
delete_na_asian <- function(x) {
x <- Recode(
x,
"-2 = NA;
7 = NA;
8 = NA;
9 = NA;
97 = NA;
98 = NA;
99 = NA;
-1 = NA"
)
return(x)
} # Funktion um die NAs im asian Datensatz zu bestimmen
asian_3 <- asian_raw %>%
rename(
educ = se5,
trust_gov = q9,
trust_parliament = q11,
trust_police = q14,
trust_courts = q8,
sex = se2,
income = se13a,
work = se9
) %>%
mutate_at(
vars(
income, trust_gov, trust_parliament,
trust_police, trust_courts, work, sex
),
delete_na_asian
) %>% # NAs deleten
mutate(
trust_gov = 5 - trust_gov,
trust_parliament = 5 - trust_parliament,
trust_police = 5 - trust_police,
trust_courts = 5 - trust_courts,
sex = sex - 1, # sex (0/1) codieren
income = Recode(
income,
"0 = NA"
),
income = 5 - income,
work = Recode(
work, # work (0/1) codieren
"2 = 0"
),
age = Recode(
se3a, # missing values l?schen
"-1 = NA"
),
# demtoday = Recode(
# q91,
# "-1 = NA;
# 97 = NA;
# 98 = NA;
# 99 = NA"
# ),
educ = Recode(
educ,
"-1 = NA;
98 = NA;
99 = NA"
),
cntry = to_label(country),
year = as.numeric(format(ir9, "%Y"))
) %>%
select(
cntry, year, age, sex, income, educ, work,
trust_gov, trust_parliament, trust_police, trust_courts
)
asian_3
save(asian_3, file = "codebooks/singles/asian_3.Rdata")
load(myanmar_raw_url)
needed <- function(data) {
ss <- data %>%
rename(
educ = se5,
trust_gov = q9,
trust_parliament = q11,
trust_police = q14,
trust_courts = q8,
sex = se2,
income = se13a,
work = se9
) %>%
mutate_at(
vars(
trust_gov, trust_parliament,
trust_police, trust_courts, work, sex
),
delete_na_asian
) %>% # NAs deleten
mutate(
trust_gov = 5 - trust_gov,
trust_parliament = 5 - trust_parliament,
trust_police = 5 - trust_police,
trust_courts = 5 - trust_courts,
sex = sex - 1, # sex (0/1) codieren
income = Recode(
income,
"0 = NA;
97 = NA;
98 = NA;
99 = NA;
-1 = NA"
),
work = Recode(
work, # work (0/1) codieren
"2 = 0"
),
age = Recode(
se3_2, # missing values l?schen
"-1 = NA"
),
# demtoday = Recode(
# q94,
# "-1 = NA;
# 97 = NA;
# 98 = NA;
# 99 = NA"
# ),
educ = Recode(
educ,
"-1 = NA;
98 = NA;
99 = NA"
),
cntry = to_label(country),
year = year
) %>%
select(
cntry, year, age, sex, income, educ, work,
trust_gov, trust_parliament, trust_police, trust_courts
)
return(ss)
}
myanmar <- needed(myanmar_raw)
load(mongolia_raw_url)
load(philip_raw_url)
load(taiwan_raw_url)
load(thai_raw_url)
load(malay_raw_url)
load(singapore_raw_url)
load(sk_raw_url)
load(cambodia_raw_url)
mongolia <- needed(mongolia_raw)
philip <- needed(philip_raw)
thai <- needed(thai_raw)
malay <- needed(malay_raw)
singapore <- needed(singapore_raw) # Singapore hat extrem viele Missing values
sk <- needed(sk_raw)
cambodia <- needed(cambodia_raw)
save(myanmar, file = "codebooks/singles/myanmar.Rdata")
save(mongolia, file = "codebooks/singles/mongolia.Rdata")
save(philip, file = "codebooks/singles/philip.Rdata")
save(thai, file = "codebooks/singles/thai.Rdata")
save(malay, file = "codebooks/singles/malay.Rdata")
save(singapore, file = "codebooks/singles/singapore.Rdata")
save(sk, file = "codebooks/singles/sk.Rdata")
save(cambodia, file = "codebooks/singles/cambodia.Rdata")
# Taiwan Problem: Income only has 3 categories
taiwan <- taiwan_raw %>%
rename(
educ = se5,
trust_gov = q9,
trust_parliament = q11,
trust_police = q14,
trust_courts = q8,
sex = se2,
income = se14a,
work = se9
) %>%
mutate_at(
vars(
income, trust_gov, trust_parliament,
trust_police, trust_courts, work, sex
),
delete_na_asian
) %>% # NAs deleten
mutate(
trust_gov = 5 - trust_gov,
trust_parliament = 5 - trust_parliament,
trust_police = 5 - trust_police,
trust_courts = 5 - trust_courts,
sex = sex - 1, # sex (0/1) codieren
income = Recode(
4 - income,
"8 = NA;
9 = NA"
),
work = Recode(
work, # work (0/1) codieren
"2 = 0"
),
age = Recode(
se3_2, # missing values l?schen
"-1 = NA"
),
# demtoday = Recode(
# q94,
# "-1 = NA;
# 97 = NA;
# 98 = NA;
# 99 = NA"
# ),
educ = Recode(
educ,
"-1 = NA;
98 = NA;
99 = NA"
),
cntry = to_label(country),
year = year
) %>%
select(
cntry, year, age, sex, income, educ, work,
trust_gov, trust_parliament, trust_police, trust_courts
)
save(taiwan, file = "codebooks/singles/taiwan.Rdata")
asian_3 %<>%
mutate_at(
vars(
income, educ,
trust_gov, trust_parliament,
trust_police, trust_courts
),
range01
)
myanmar %<>%
mutate_at(
vars(
income, educ,
trust_gov, trust_parliament,
trust_police, trust_courts
),
range01
)
mongolia %<>%
mutate_at(
vars(
income, educ,
trust_gov, trust_parliament,
trust_police, trust_courts
),
range01
)
philip %<>%
mutate_at(
vars(
income, educ,
trust_gov, trust_parliament,
trust_police, trust_courts
),
range01
)
taiwan %<>%
mutate_at(
vars(
income, educ,
trust_gov, trust_parliament,
trust_police, trust_courts
),
range01
)
thai %<>%
mutate_at(
vars(
income, educ,
trust_gov, trust_parliament,
trust_police, trust_courts
),
range01
)
malay %<>%
mutate_at(
vars(
income, educ,
trust_gov, trust_parliament,
trust_police, trust_courts
),
range01
)
singapore %<>%
mutate_at(
vars(
income, educ,
trust_gov, trust_parliament,
trust_police, trust_courts
),
range01
)
sk %<>%
mutate_at(
vars(
income, educ,
trust_gov, trust_parliament,
trust_police, trust_courts
),
range01
)
cambodia %<>%
mutate_at(
vars(
income, educ,
trust_gov, trust_parliament,
trust_police, trust_courts
),
range01
)
asian <- rbind(
asian_3, myanmar, cambodia, sk, singapore, malay, thai, taiwan, philip,
cambodia, mongolia
) %>% as.tbl()
asian
afro %<>%
mutate(survey = rep("afro", nrow(afro))) %>%
mutate(cntry = countrycode(cntry, "country.name", "country.name"))
latino %<>%
mutate(survey = rep("latino", nrow(latino))) %>%
mutate(cntry = countrycode(cntry, "country.name", "country.name"))
americas %<>%
mutate(survey = rep("americas", nrow(americas))) %>%
mutate(cntry = countrycode(cntry, "country.name", "country.name"))
asian %<>%
mutate(survey = rep("asian", nrow(asian))) %>%
mutate(cntry = countrycode(cntry, "country.name", "country.name"))
wvs %<>%
mutate(survey = rep("wvs", nrow(wvs))) %>%
mutate(cntry = countrycode(cntry, "country.name", "country.name")) %>%
mutate_at(
vars(
income, educ,
trust_gov, trust_parliament,
trust_police, trust_courts
),
range01
)
ESS %<>%
mutate(survey = rep("ESS", nrow(ESS))) %>%
mutate(cntry = countrycode(cntry, "country.name", "country.name")) %>%
mutate_at(
vars(
income, educ,
trust_gov, trust_parliament,
trust_police, trust_courts
),
stdz
) %>%
mutate_at(
vars(
income, educ,
trust_gov, trust_parliament,
trust_police, trust_courts
),
range01
)
unique(ESS$cntry)
[1] "Albania" "Belgium" "Bulgaria" "Switzerland" "Cyprus" "Czechia"
[7] "Germany" "Denmark" "Estonia" "Spain" "Finland" "France"
[13] "United Kingdom" "Hungary" "Ireland" "Israel" "Iceland" "Italy"
[19] "Lithuania" "Netherlands" "Norway" "Poland" "Portugal" "Russia"
[25] "Sweden" "Slovenia" "Slovakia" "Ukraine" "Kosovo"
unique(asian$cntry)
[1] "Japan" "Hong Kong SAR China" "South Korea" "China"
[5] "Mongolia" "Philippines" "Taiwan" "Thailand"
[9] "Indonesia" "Singapore" "Vietnam" "Cambodia"
[13] "Malaysia" "Myanmar (Burma)"
unique(wvs$cntry)
[1] "Algeria" "Argentina" "Armenia" "Australia"
[5] "Azerbaijan" "Bahrain" "Belarus" "Brazil"
[9] "Colombia" "Cyprus" "Chile" "China"
[13] "Ecuador" "Egypt" "Estonia" "Georgia"
[17] "Germany" "Ghana" "Hong Kong SAR China" "India"
[21] "Iraq" "Japan" "Jordan" "Kazakhstan"
[25] "Kuwait" "Kyrgyzstan" "Lebanon" "Libya"
[29] "Malaysia" "Mexico" "Morocco" "Netherlands"
[33] "New Zealand" "Nigeria" "Pakistan" "Palestinian Territories"
[37] "Peru" "Philippines" "Poland" "Qatar"
[41] "Romania" "Russia" "Rwanda" "Singapore"
[45] "Slovenia" "South Korea" "South Africa" "Spain"
[49] "Sweden" "Taiwan" "Thailand" "Trinidad & Tobago"
[53] "Tunisia" "Turkey" "Ukraine" "United States"
[57] "Uruguay" "Uzbekistan" "Yemen" "Zimbabwe"
unique(latino$cntry)
[1] "Argentina" "Bolivia" "Brazil" "Colombia" "Costa Rica"
[6] "Chile" "Ecuador" "El Salvador" "Spain" "Guatemala"
[11] "Honduras" "Mexico" "Nicaragua" "Panama" "Paraguay"
[16] "Peru" "Dominican Republic" "Uruguay" "Venezuela"
unique(americas$cntry)
[1] "Bahamas" "Barbados" "Belize" "Brazil" "Colombia"
[6] "Costa Rica" "Dominican Republic" "Ecuador" "El Salvador" "Guatemala"
[11] "Guyana" "Haiti" "Honduras" "Jamaica" "Mexico"
[16] "Nicaragua" "Panama" "Paraguay" "Peru" "Suriname"
[21] "Trinidad & Tobago" "Uruguay" "Bolivia" "Canada"
unique(afro$cntry)
[1] "Algeria" "Burundi" "Benin" "Burkina Faso"
[5] "Botswana" "Cameroon" "Côte d’Ivoire" "Cape Verde"
[9] "Egypt" "Ghana" "Guinea" "Kenya"
[13] "Lesotho" "Liberia" "Madagascar" "Mauritius"
[17] "Mali" "Malawi" "Mozambique" "Morocco"
[21] "Namibia" "Niger" "Nigeria" "South Africa"
[25] "Senegal" "Sierra Leone" "Sudan" "Swaziland"
[29] "Tanzania" "Togo" "Tunisia" "Uganda"
[33] "Zambia" "Zimbabwe" "Gabon" "São Tomé & PrÃncipe"
merged <- rbind(wvs, latino, afro, americas, asian, ESS)
merged %<>%
# create dummies
mutate(
wvs = ifelse(survey == "wvs", 1, 0),
afro = ifelse(survey == "afro", 1, 0),
latino = ifelse(survey == "latino", 1, 0),
americas = ifelse(survey == "americas", 1, 0),
asian = ifelse(survey == "asian", 1, 0),
ESS = ifelse(survey == "ESS", 1, 0)
) %>%
# filter bad countries
filter(!(cntry == "Egypt" & year == 2013)) %>% # exclude Egypt 2013
filter(!(cntry == "Libya" & year == 2014)) %>% # exclude Libya 2014
filter(!(cntry == "Mali" & year == 2012)) %>% # exclude Mali 2012
filter(!(cntry == "Yemen" & year == 2012)) %>% # exclude Yemen 2012
filter(!(cntry == "Palestine, State of" & year == 2013)) # exclude Palestine 2013
# adding weight
not_character <- function(x) {
!(is.character(x))
}
merged %<>%
group_by(cntry) %>%
tally() %>%
mutate(weight = 1000 / n) %>%
select(cntry, weight) %>%
left_join(merged, "cntry") %>%
mutate_if(not_character, as.numeric)
# select(cntry, year) %>%
# unique %>%
# View
merged
table(merged$wvs)
0 1
306779 82618
table(merged$afro)
0 1
286241 103156
table(merged$latino)
0 1
346484 42913
table(merged$americas)
0 1
315547 73850
table(merged$asian)
0 1
357210 32187
table(merged$ESS)
0 1
334724 54673
#TODO todor::
merged %>%
select(trust_gov, trust_parliament,
trust_police, trust_courts) %>%
psych::alpha()
Reliability analysis
Call: psych::alpha(x = .)
raw_alpha std.alpha G6(smc) average_r S/N ase mean sd
0.81 0.81 0.78 0.52 4.3 0.0005 0.49 0.26
lower alpha upper 95% confidence boundaries
0.81 0.81 0.81
Reliability if an item is dropped:
raw_alpha std.alpha G6(smc) average_r S/N alpha se
trust_gov 0.77 0.77 0.69 0.52 3.3 0.00065
trust_parliament 0.74 0.74 0.67 0.49 2.9 0.00072
trust_police 0.79 0.79 0.73 0.56 3.8 0.00057
trust_courts 0.75 0.75 0.69 0.50 3.0 0.00070
Item statistics
n raw.r std.r r.cor r.drop mean sd
trust_gov 364295 0.81 0.80 0.71 0.63 0.49 0.34
trust_parliament 368645 0.82 0.82 0.75 0.67 0.45 0.32
trust_police 382631 0.77 0.76 0.63 0.57 0.52 0.33
trust_courts 372752 0.82 0.82 0.73 0.66 0.50 0.32
merged %>%
select(trust_gov, trust_parliament,
trust_police, trust_courts) %>%
psych::KMO()
Kaiser-Meyer-Olkin factor adequacy
Call: psych::KMO(r = .)
Overall MSA = 0.76
MSA for each item =
trust_gov trust_parliament trust_police trust_courts
0.75 0.74 0.79 0.77
merged %<>%
select(trust_gov, trust_parliament,
trust_police, trust_courts) %>%
mutate_all(as.numeric) %>%
psych::fa(weight = merged$weight) %>%
psych::predict.psych(data = merged %>%
select(trust_gov, trust_parliament,
trust_police, trust_courts)) %>%
as.data.frame() %>%
transmute(gov_trust = range01(MR1)) %>%
cbind(merged)
merged
load(vdems_start_url)
vdems_sub <- vdems_start %>% filter(year %in% 2000:2010)
#tibble(id = 1:1896)
#table(vdems_sub$country_name)
vdem <- vdems_start %>%
filter(year %in% 2000:2010) %>%
group_by(country_name) %>%
tally %>%
mutate(cntry = unique(country_name)) %>%
#DCI Variables
mutate(delib10 = vdems_sub %>%
dcast(country_name ~ year,
value.var=c("v2xdl_delib")) %>%
select(`2000`:`2010`) %>%
rowMeans) %>%
mutate(consult10 = vdems_sub %>%
dcast(country_name ~ year,
value.var=c("v2dlconslt")) %>%
select(`2000`:`2010`) %>%
rowMeans) %>%
mutate(reason10 = vdems_sub %>%
dcast(country_name ~ year,
value.var=c("v2dlreason")) %>%
select(`2000`:`2010`) %>%
rowMeans) %>%
mutate(common10 = vdems_sub %>%
dcast(country_name ~ year,
value.var=c("v2dlcommon")) %>%
select(`2000`:`2010`) %>%
rowMeans) %>%
mutate(countr10 = vdems_sub %>%
dcast(country_name ~ year,
value.var=c("v2dlcountr")) %>%
select(`2000`:`2010`) %>%
rowMeans) %>%
mutate(engage10 = vdems_sub %>%
dcast(country_name ~ year,
value.var=c("v2dlengage")) %>%
select(`2000`:`2010`) %>%
rowMeans) %>%
mutate(delibdem10 = vdems_sub %>%
dcast(country_name ~ year,
value.var=c("v2x_delibdem")) %>%
select(`2000`:`2010`) %>%
rowMeans) %>%
# Control Variables
mutate(polity10 = vdems_sub %>%
dcast(country_name ~ year,
value.var=c("e_fh_ipolity2")) %>%
select(`2000`:`2010`) %>%
rowMeans) %>%
mutate(poly10 = vdems_sub %>%
dcast(country_name ~ year,
value.var=c("v2x_polyarchy")) %>%
select(`2000`:`2010`) %>%
rowMeans) %>%
mutate(rol10 = vdems_sub %>%
dcast(country_name ~ year,
value.var=c("e_wbgi_rle")) %>%
select(`2000`:`2010`) %>%
rowMeans) %>%
# mutate(gdp10 = vdems_sub %>% filter(year %in% 2000:2008) %>%
# dcast(country_name ~ year,
# value.var=c("e_GDP_Per_Cap_Haber_Men_2")) %>%
# select(`2000`:`2010`) %>%
# rowMeans) %>%
mutate(riw10 = vdems_sub %>%
dcast(country_name ~ year,
value.var=c("e_v2x_regime_ci")) %>%
select(`2000`:`2010`) %>%
rowMeans) %>%
mutate(corecivil10 = vdems_sub %>%
dcast(country_name ~ year,
value.var=c("v2xcs_ccsi")) %>%
select(`2000`:`2010`) %>%
rowMeans) %>%
mutate(pop10 = vdems_sub %>%
dcast(country_name ~ year,
value.var=c("e_mipopula")) %>%
select(`2000`:`2010`) %>%
rowMeans) %>%
mutate(corruption10 = vdems_sub %>%
dcast(country_name ~ year,
value.var=c("v2x_corr")) %>%
select(`2000`:`2010`) %>%
rowMeans) %>%
mutate(polkill10 = vdems_sub %>%
dcast(country_name ~ year,
value.var=c("v2x_clphy")) %>%
select(`2000`:`2010`) %>%
rowMeans) %>%
mutate(educ10 = vdems_sub %>%
dcast(country_name ~ year,
value.var=c("e_peaveduc")) %>%
select(`2000`:`2010`) %>%
rowMeans) %>%
mutate(equal_distrib10 = vdems_sub %>%
dcast(country_name ~ year,
value.var=c("v2xeg_eqdr")) %>%
select(`2000`:`2010`) %>%
rowMeans) %>%
mutate(div_party10 = vdems_sub %>%
dcast(country_name ~ year,
value.var=c("v2x_divparctrl")) %>%
select(`2000`:`2010`) %>%
rowMeans) %>%
mutate(div_power10 = vdems_sub %>%
dcast(country_name ~ year,
value.var=c("v2x_feduni")) %>%
select(`2000`:`2010`) %>%
rowMeans) %>%
mutate(accountability10 = vdems_sub %>%
dcast(country_name ~ year,
value.var=c("v2x_accountability")) %>%
select(`2000`:`2010`) %>%
rowMeans) %>%
mutate(directdem10 = vdems_sub %>%
dcast(country_name ~ year,
value.var=c("v2xdd_dd")) %>%
select(`2000`:`2010`) %>%
rowMeans) %>%
mutate(eq_educ10 = vdems_sub %>%
dcast(country_name ~ year,
value.var=c("v2peedueq")) %>%
select(`2000`:`2010`) %>%
rowMeans) %>%
mutate(eq_health10 = vdems_sub %>%
dcast(country_name ~ year,
value.var=c("v2pehealth")) %>%
select(`2000`:`2010`) %>%
rowMeans) %>%
mutate(controlcorruption10 = vdems_sub %>%
dcast(country_name ~ year,
value.var=c("e_wbgi_cce")) %>%
select(`2000`:`2010`) %>%
rowMeans) %>%
mutate(eff10 = vdems_sub %>%
dcast(country_name ~ year,
value.var=c("e_wbgi_gee")) %>%
select(`2000`:`2010`) %>%
rowMeans) %>%
mutate(stability10 = vdems_sub %>%
dcast(country_name ~ year,
value.var=c("e_wbgi_pse")) %>%
select(`2000`:`2010`) %>%
rowMeans) %>%
mutate(unified_dem10 = vdems_sub %>%
dcast(country_name ~ year,
value.var=c("e_uds_mean")) %>%
select(`2000`:`2010`) %>%
rowMeans) %>%
mutate(gdp_growth10 = vdems_sub %>%
dcast(country_name ~ year,
value.var=c("e_migdpgrolns")) %>%
select(`2000`:`2010`) %>%
rowMeans) %>%
mutate(infla10 = vdems_sub %>%
dcast(country_name ~ year,
value.var=c("e_miinflat")) %>%
select(`2000`:`2010`) %>%
rowMeans) %>%
# mutate(lifeexp10 = vdems_sub %>%
# dcast(country_name ~ year,
# value.var=c("e_pelifeex")) %>%
# select(`2000`:`2010`) %>%
# rowMeans) %>%
mutate(urbanratio10 = vdems_sub %>%
dcast(country_name ~ year,
value.var=c("e_miurbani")) %>%
select(`2000`:`2010`) %>%
rowMeans) %>%
# mutate(gini10 = vdems_sub %>%
# dcast(country_name ~ year,
# value.var=c("e_peginiwi")) %>%
# select(`2000`:`2010`) %>%
# rowMeans) %>%
# Dummy variables
mutate(pol_round = round(polity10 * 2 - 10)) %>%
mutate(polity_demdummy = ifelse(pol_round > 5, 1, 0)) %>%
mutate(polity_anodummy = ifelse(pol_round >= -5 & pol_round <= 5, 1, 0)) %>%
mutate(polity_autodummy = ifelse(pol_round < -5, 1, 0)) %>%
mutate(regime = case_when(
polity_autodummy == 1 ~ "auto",
polity_anodummy == 1 ~ "ano",
polity_demdummy == 1 ~ "demo"
)
) %>%
mutate(regime = factor(regime, levels = c("demo", "ano", "auto"))) %>%
mutate(cntry = ifelse(str_detect(cntry, "ietnam"), "Vietnam", cntry)) %>%
mutate(cntry = countrycode(cntry,"country.name","country.name")) %>%
select(-n)
# vdem$cntry[40] <- "Viet Nam"
# ifelse(round(vdem$polity10 * 2 -10) >= -5 & round(vdem$polity10 * 2 -10) <= 5, 1, 0)
table(vdem$regime)
demo ano auto
72 77 18
print(levels(vdem$regime))
[1] "demo" "ano" "auto"
# DURATION OF REGIME?! e_democracy_duration
load("data/qog.Rdata")
count_na <- function(x) sum(is.na(x))
qog10 <- qog %>%
filter(year %in% 2000:2010) %>%
mutate(count_na = apply(., 1, count_na)) %>%
filter(count_na < 2050) %>%
mutate(cntry = countrycode(ccodealp, "iso3c","country.name"))
Some values were not matched unambiguously: SCG
qog10 <- qog %>%
filter(year %in% 2000:2010) %>%
mutate(count_na = apply(., 1, count_na)) %>%
filter(count_na < 2050) %>%
mutate(cntry = countrycode(ccodealp, "iso3c","country.name")) %>%
group_by(cntry) %>%
tally() %>%
mutate(ethnic10 = qog10 %>%
dcast(cntry ~ year,
value.var = c("al_ethnic"),
fun.aggregate = mean) %>%
select(`2000`:`2010`) %>%
rowMeans) %>%
mutate(gdp10 = qog10 %>%
dcast(cntry ~ year,
value.var = c("gle_cgdpc"),
fun.aggregate = mean) %>%
select(`2000`:`2010`) %>%
rowMeans) %>%
mutate(corrupt10 = qog10 %>%
dcast(cntry ~ year,
value.var = c("bci_bci"),
fun.aggregate = mean) %>%
select(`2000`:`2010`) %>%
rowMeans) %>%
mutate(lifeexp10 = qog10 %>%
dcast(cntry ~ year,
value.var = c("ihme_lebs0001"),
fun.aggregate = mean) %>%
select(`2000`:`2010`) %>%
rowMeans) %>%
mutate(mortinf10 = qog10 %>%
dcast(cntry ~ year,
value.var = c("wdi_mortinf"),
fun.aggregate = mean) %>%
select(`2000`:`2010`) %>%
rowMeans) %>%
mutate(urbanpop10 = qog10 %>%
dcast(cntry ~ year,
value.var = c("wdi_popurb"),
fun.aggregate = mean) %>%
select(`2000`:`2010`) %>%
rowMeans) %>%
mutate(qogpop10 = qog10 %>%
dcast(cntry ~ year,
value.var = c("pwt_pop"),
fun.aggregate = mean) %>%
select(`2000`:`2010`) %>%
rowMeans) %>%
# mutate(work10 = qog10 %>%
# dcast(cntry ~ year,
# value.var = c("wdi_unemp"),
# fun.aggregate = mean) %>%
# select(`2000`:`2010`) %>%
# rowMeans) %>%
mutate(frac_elites10 = qog10 %>% filter(year %in% 2004:2010) %>%
dcast(cntry ~ year,
value.var = c("ffp_fe"),
fun.aggregate = mean) %>%
select(`2004`:`2010`) %>%
rowMeans) %>%
mutate(glob10 = qog10 %>%
dcast(cntry ~ year,
value.var = c("dr_ig"),
fun.aggregate = mean) %>%
select(`2000`:`2010`) %>%
rowMeans) %>%
select(-n)
Some values were not matched unambiguously: SCG
# mutate(al_ethnic = as.numeric(al_ethnic)) %>%
qog10
# qog10 %>%
# # select(cntry, cname, ccodecow) %>%
# group_by(cntry) %>%
# slice(1) %>%
# arrange(cntry)
# #
# # countrycode()
#
# qog %>%
# filter(year %in% 2000:2010) %>%
# filter(str_detect(cname, "Germany")) %>%
# select(cname, al_ethnic, gle_cgdpc)
#
#
qog %>%
filter(year %in% 2000:2010) %>%
filter(str_detect(cname, "Taiwan")) %>%
select(cname, wdi_lifexp)
# options(scipen=999)
load("data/swiid6_1.rda")
gini <- swiid_summary
gini_sub <- gini %>% filter(year %in% 2000:2010)
gini %<>%
filter(year %in% 2000:2010) %>%
group_by(country) %>%
tally %>%
mutate(cntry = unique(country)) %>%
#DCI Variables
mutate(gini10 = gini_sub %>%
dcast(country ~ year,
value.var = c("gini_disp")) %>%
select(`2000`:`2010`) %>%
rowMeans) %>%
mutate(cntry = countrycode(cntry,"country.name","country.name")) %>%
select(cntry, gini10)
Some values were not matched unambiguously: Micronesia
level2 <- merge(x = qog10, y = vdem, by = "cntry") %>% merge(gini, by = "cntry")
level2
# load("data/level1.Rdata")
combined <- merge(x = merged, y = level2, by = "cntry") %>%
mutate(cntryears = paste(cntry, year))
#combined$cntryears <- paste(combined$cntry,combined$year)
vdem2 <- vdems_start %>%
filter(year %in% 2010:2015) %>%
mutate(country_name = ifelse(str_detect(country_name, "ietnam"), "Vietnam", country_name)) %>%
mutate(cntry = countrycode(country_name,"country.name","country.name")) #%>%
# select(cntry, country_name)
# vdem2$cntry[996] <- "Viet Nam"
# vdem2$cntry[997] <- "Viet Nam"
# vdem2$cntry[998] <- "Viet Nam"
# vdem2$cntry[999] <- "Viet Nam"
# vdem2$cntry[1000] <- "Viet Nam"
# vdem2$cntry[1001] <- "Viet Nam"
# v2x_freexp_thick freedom of expression
combined <- vdem2 %>%
mutate(cntryears = paste(cntry, year)) %>%
mutate(discuss_unsel = v2xcl_disc) %>%
select(cntryears, discuss_unsel) %>%
merge(combined, by = "cntryears") %>%
plyr::ddply(~cntry,
summarise,
discuss = mean(discuss_unsel, na.rm=T)) %>%
merge(combined, by = "cntry")
save(combined,file = "data/combined.Rdata")
save(level2,file = "data/level2.Rdata")
macro <- combined %>%
# mutate(gov_trust = range01(gov_trust)) %>%
# mutate(demtoday = range01(demtoday)*100) %>%
group_by(cntry) %>%
dplyr::summarise(
mean_gov = mean(gov_trust, na.rm=T),
mean_gov_low = mean(gov_trust_low, na.rm=T),
mean_gov_high = mean(gov_trust_high, na.rm=T),
discuss = mean(discuss, na.rm=T),
) %>%
merge(level2, by = "cntry") %>%
zap_inf() %>%
mutate(urbanratio10 = ifelse(is.na(urbanratio10), urbanpop10, urbanratio10)) %>%
mutate(pop10 = ifelse(is.na(pop10), qogpop10 * 1000000, pop10)) %>%
select(cntry, mean_gov, mean_gov_low, mean_gov_high,
delib10:polity10,
pol_round, polity_demdummy, polity_anodummy,
polity_autodummy, polity_autodummy,
regime, discuss, #discuss_round,
gdp10, corrupt10, lifeexp10, pop10,
poly10, riw10, unified_dem10, urbanratio10) %>%
drop_na(mean_gov) %>%
mutate(count_na = apply(., 1, count_na)) %>%
mutate_at(vars(delib10:polity10, polity_demdummy:polity_autodummy, discuss:urbanratio10), range01)
macro_dem <- macro %>%
filter(polity_demdummy == 1) %>%
mutate_at(vars(delib10:polity10, polity_demdummy:polity_autodummy, discuss:urbanratio10), range01)
macro_aut <- macro %>%
filter(polity_demdummy == 0) %>%
mutate_at(vars(delib10:polity10, polity_demdummy:polity_autodummy, discuss:urbanratio10), range01)
# table_stuff2<-subset(table_stuff,
# !is.na(table_stuff$regime) &
# table_stuff$cntry!="Qatar" &
# table_stuff$cntry!="Uzbekistan")
save(macro, file = "data/macro.Rdata")
save(macro_dem, file = "data/macro_dem.Rdata")
save(macro_aut, file = "data/macro_aut.Rdata")
merged2 <- merged %>%
mutate(gov_trust = trust_gov + trust_parliament +
trust_police + trust_courts) %>%
filter(!is.na(gov_trust))
merged3 <- merged %>%
mutate(gov_trust = trust_gov + trust_parliament +
trust_police + trust_courts) %>%
filter(is.na(gov_trust))
svy.df <- survey::svydesign(id= ~1,
weights= ~weight,
data= merged)
model <- '# measurement model 1
gov_trust2 =~ 1*trust_gov + trust_parliament +
trust_police + trust_courts
trust_gov ~~ trust_parliament
'
merged <- merged %>%
mutate_at(vars(trust_gov, trust_parliament,
trust_police, trust_courts), as.numeric)
# cor(na.omit(data.frame(merged$trust_gov,
# merged$trust_police,
# merged$trust_courts,
# merged$trust_parliament,
# merged$demtoday)))
lavaan_model1<-cfa(model, meanstructure = T,
data = as.data.frame(merged),
estimator= "MLM")
fit_a1<-lavaan.survey(lavaan_model1,
estimator= "MLM", survey.design=svy.df)
summary(fit_a1, standardized=TRUE,fit.measures = TRUE, rsq = T)
merged4<-cbind(merged2, predict(fit_a1, newdata = merged2))
merged4$gov_trust2<-range01(merged4$gov_trust2)
# head(merged4)
merged<-plyr::rbind.fill(merged3,merged4)
merged$gov_trust<-merged$gov_trust2
head(merged)
compare_cntry<-data.frame(table(merged$cntry,merged$year))
compare_cntry<-tidyr::spread(compare_cntry,Var2,Freq)
compare_cntry[compare_cntry==0]<-100000
#compare_cntry<-na.omit(compare_cntry)
indie<-as.numeric(apply(compare_cntry[,-1],1,sum))
compare_cntry$double<-indie<900000
compare_cntry[compare_cntry==100000]<-0
compare_cntry2 <- subset(compare_cntry,compare_cntry$double==TRUE)
compare_cntry3 <- subset(merged,merged$cntry %in% compare_cntry2$Var1)
y1<-subset(compare_cntry3,compare_cntry3$cntry=="Belize" &
compare_cntry3$year==2012)$gov_trust
y2<-subset(compare_cntry3,compare_cntry3$cntry=="Belize" &
compare_cntry3$year==2014)$gov_trust
t.test(y1,y2)
y1<-subset(compare_cntry3,compare_cntry3$cntry=="Bolivia (Plurinational State of)" &
compare_cntry3$year==2012)$gov_trust
y2<-subset(compare_cntry3,compare_cntry3$cntry=="Bolivia (Plurinational State of)" &
compare_cntry3$year==2013)$gov_trust
t.test(y1,y2)
y1<-subset(compare_cntry3,compare_cntry3$cntry=="South Africa" &
compare_cntry3$year==2011)$gov_trust
y2<-subset(compare_cntry3,compare_cntry3$cntry=="South Africa" &
compare_cntry3$year==2013)$gov_trust
t.test(y1,y2)
subset(merged,merged$year==2012)
library(dplyr)
compare_cntry4 <- compare_cntry3 %>%
group_by(cntry,year) %>%
summarise_all(funs(mean(., na.rm=TRUE)))
compare_cntry4$cntryear<-paste(compare_cntry4$cntry,compare_cntry4$year)
as.data.frame(compare_cntry4[,c(17,8)])
?ddply
head(afro)
afrocntry<-unique(afro$cntry)
latinocntry<-unique(latino2013$cntry)
arabcntry<-unique(arab3$cntry)
wvscntry<-unique(wvs$cntry)
cntry_table<- data.frame(as.character(wvscntry),
c(as.character(arabcntry),rep("-",48)),
c(as.character(latinocntry),rep("-",41)),
c(as.character(afrocntry),rep("-",24)))
colnames(cntry_table) <- c("wvs","arab","latino","afro")
arrange(cntry_table, wvs, afro)
table(combined$politcat.x)
mplusdata <- combined %>% dplyr::select(cntry, delib10,
trust_gov, trust_parliament,
trust_police,trust_courts,weight)
mplusdata <- na.omit(mplusdata)
mplusdata$cntry <- as.numeric(mplusdata$cntry)
write_csv(mplusdata, path = "mplusdata.csv", col_names = F)
mplusdata2 <- combined %>% dplyr::select(cntry, delib10,
gov_trust,weight)
mplusdata2 <- na.omit(mplusdata2)
mplusdata2$cntry <- as.numeric(mplusdata2$cntry)
write_csv(mplusdata2, path = "mplusdat2a.csv", col_names = F)
mplusdata2_dem <- combined_dem %>% dplyr::select(cntry, delib10,
gov_trust,weight)
mplusdata2_dem <- na.omit(mplusdata2_dem)
mplusdata2_dem$cntry <- as.numeric(mplusdata2_dem$cntry)
write_csv(mplusdata2_dem, path = "mplusdat2_dema.csv", col_names = F)
mplusdata2_aut <- combined_aut %>% dplyr::select(cntry, delib10,
gov_trust,weight)
mplusdata2_aut <- na.omit(mplusdata2_aut)
mplusdata2_aut$cntry <- as.numeric(mplusdata2_aut$cntry)
write_csv(mplusdata2_aut, path = "mplusdat2_auta.csv", col_names = F)
combined <- merge(combined, physi2_s, by = "cntry")
combined_dem <- subset(combined,combined$polity_demdummy==1)
mplusdata_dem <- combined_dem %>% dplyr::select(cntry, delib10,
trust_gov, trust_parliament,
trust_police,trust_courts,weight)
mplusdata_dem <- na.omit(mplusdata_dem)
mplusdata_dem$cntry <- as.numeric(mplusdata_dem$cntry)
write_csv(mplusdata_dem, path = "mplusdata_dem.csv", col_names = F)
combined_aut <- subset(combined,combined$polity_demdummy==0)
mplusdata_aut <- combined_aut %>% dplyr::select(cntry, delib10,
trust_gov, trust_parliament,
trust_police,trust_courts,weight)
mplusdata_aut <- na.omit(mplusdata_aut)
mplusdata_aut$cntry <- as.numeric(mplusdata_aut$cntry)
write_csv(mplusdata_aut, path = "mplusdata_aut.csv", col_names = F)
#data_wids <- dcast(merged, cntry~year,
# value.var=c("year"))
#data_wids2 <- as.data.frame(lapply(data_wids[,-1],function(n) 0<n))
#data_wids3 <- as.data.frame(apply(data_wids2,2,as.numeric))
#data_wids3 <- cbind(data_wids[,1],data_wids3)
#names(data_wids3)[1]<-"cntry"
#table_stuff <- merge(data_wids3 ,table_stuff, by="cntry")
#table_stuff$polity10[table_stuff$cntry=="Tunisia"] <- 5.32382
#table_stuff2$polity10[table_stuff2$cntry=="Tunisia"] <- 5.32382
head(table_stuff)
cor(na.omit(data.frame(table_stuff$legit,table_stuff$legit2,table_stuff$legit3,
table_stuff$mean_gov)))
table_stuff$gni <- table_stuff$gni_c
table_stuff$gni_c[table_stuff$gni <= 1025] <- "low"
table_stuff$gni_c[table_stuff$gni > 1026 & table_stuff$gni <= 4035] <- "lower-middle"
table_stuff$gni_c[table_stuff$gni > 4036 & table_stuff$gni <= 12475] <- "upper-middle"
table_stuff$gni_c[table_stuff$gni > 12475] <- "high"
table_stuff$gni_c2 <- table_stuff$gni_c
table_stuff$gni_c2[table_stuff$gni_c == "lower-middle"] <- "low"
table_stuff$gni_c2[table_stuff$gni_c == "upper-middle"] <- "high"
table(table_stuff$gni_c)
table(table_stuff$gni_c2)
The cut-off points are HDI of less than 0.550
for low human development, 0.550-0.699 for medium human
development, 0.700-0.799 for high human development and
0.800 or greater for very high human development.
#table_stuff$hdi_c <- table_stuff$hdi
#table_stuff$hdi_c[table_stuff$hdi < 0.550] <- "low"
#table_stuff$hdi_c[table_stuff$hdi >= 0.550 & table_stuff$hdi <= 0.699] <- "medium"
#table_stuff$hdi_c[table_stuff$hdi >= 0.700 & table_stuff$hdi <= 0.899] <- "high"
#table_stuff$hdi_c[table_stuff$hdi >= 0.90] <- "very high"
#table(table_stuff$hdi_c)
table(round(table_stuff$terror))
table_stuff$mean_gov2 <- table_stuff$mean_gov
table_stuff$mean_gov2[is.na(table_stuff$mean_gov2)]<-999
table_stuff$mean_gov3 <- table_stuff$mean_gov
table_stuff$mean_gov3[is.na(table_stuff$mean_gov3)]<-999
table_stuff$mean_gov4 <- table_stuff$mean_gov
table_stuff$mean_gov4[is.na(table_stuff$mean_gov4)]<-999
table_stuff$mean_gov5 <- table_stuff$mean_gov
table_stuff$mean_gov5[is.na(table_stuff$mean_gov5)]<-999
table_stuff$mean_gov6 <- table_stuff$mean_gov
table_stuff$mean_gov6[is.na(table_stuff$mean_gov6)]<-999
table_stuff$mean_gov7 <- table_stuff$mean_gov
table_stuff$mean_gov7[is.na(table_stuff$mean_gov7)]<-999
table_stuff$mean_gov8 <- table_stuff$mean_gov
table_stuff$mean_gov8[is.na(table_stuff$mean_gov8)]<-999
table_stuff$mean_gov9 <- table_stuff$mean_gov
table_stuff$mean_gov9[is.na(table_stuff$mean_gov9)]<-999
table_stuff$physviol2 <- table_stuff$physviol
table_stuff$physviol2[is.na(table_stuff$physviol2)] <- 999
table_stuff$terror2 <- round(table_stuff$terror)
table_stuff$terror2[is.nan(table_stuff$terror2)] <- 999
table_stuff$discuss2 <- round(table_stuff$discuss*4)
table_stuff$discuss2[is.nan(table_stuff$discuss2)] <- 999
table(table_stuff$physviol)
table_stuff$mean_gov2[table_stuff$physviol2<=0.5 & table_stuff$physviol2>0.4] <- table_stuff$mean_gov2[table_stuff$physviol2<=0.5 & table_stuff$physviol2>0.4]-5
table_stuff$mean_gov2[table_stuff$physviol2<=0.4 & table_stuff$physviol2>0.3] <- table_stuff$mean_gov2[table_stuff$physviol2<=0.4 & table_stuff$physviol2>0.3]-10
table_stuff$mean_gov2[table_stuff$physviol2<=0.3 & table_stuff$physviol2>0.2] <- table_stuff$mean_gov2[table_stuff$physviol2<=0.3 & table_stuff$physviol2>0.2]-15
table_stuff$mean_gov2[table_stuff$physviol2<=0.2 & table_stuff$physviol2>0.1] <- table_stuff$mean_gov2[table_stuff$physviol2<=0.2 & table_stuff$physviol2>0.1]-20
table_stuff$mean_gov2[table_stuff$physviol2<=0.1 & table_stuff$physviol2>=0] <- table_stuff$mean_gov2[table_stuff$physviol2<=0.1 & table_stuff$physviol2>=0] -25
table_stuff$mean_gov2[table_stuff$mean_gov2>100] <- NA
table(table_stuff$mean_gov2)
table_stuff$mean_gov3[table_stuff$physviol2<=0.5 & table_stuff$physviol2>0.4] <- table_stuff$mean_gov3[table_stuff$physviol2<=0.5 & table_stuff$physviol2>0.4]-8
table_stuff$mean_gov3[table_stuff$physviol2<=0.4 & table_stuff$physviol2>0.3] <- table_stuff$mean_gov3[table_stuff$physviol2<=0.4 & table_stuff$physviol2>0.3]-16
table_stuff$mean_gov3[table_stuff$physviol2<=0.3 & table_stuff$physviol2>0.2] <- table_stuff$mean_gov3[table_stuff$physviol2<=0.3 & table_stuff$physviol2>0.2]-24
table_stuff$mean_gov3[table_stuff$physviol2<=0.2 & table_stuff$physviol2>0.1] <- table_stuff$mean_gov3[table_stuff$physviol2<=0.2 & table_stuff$physviol2>0.1] -32
table_stuff$mean_gov3[table_stuff$physviol2<=0.1 & table_stuff$physviol2>=0] <- table_stuff$mean_gov3[table_stuff$physviol2<=0.1 & table_stuff$physviol2>=0] -30
table_stuff$mean_gov3[table_stuff$mean_gov3>100] <- NA
table(table_stuff$mean_gov3)
table_stuff$mean_gov4[table_stuff$terror2==5] <- table_stuff$mean_gov4[table_stuff$terror2==5]-5
table_stuff$mean_gov4[table_stuff$terror2==4] <- table_stuff$mean_gov4[table_stuff$terror2==4]-10
table_stuff$mean_gov4[table_stuff$terror2==3] <- table_stuff$mean_gov4[table_stuff$terror2==3]-15
table_stuff$mean_gov4[table_stuff$mean_gov4>100] <- NA
table(table_stuff$mean_gov4)
table_stuff$mean_gov5[table_stuff$terror2==5] <- table_stuff$mean_gov5[table_stuff$terror2==5]-8
table_stuff$mean_gov5[table_stuff$terror2==4] <- table_stuff$mean_gov5[table_stuff$terror2==4]-16
table_stuff$mean_gov5[table_stuff$terror2==3] <- table_stuff$mean_gov5[table_stuff$terror2==3]-24
table_stuff$mean_gov5[table_stuff$mean_gov5>100] <- NA
table(table_stuff$mean_gov5)
table_stuff$mean_gov6[table_stuff$discuss2==2] <- table_stuff$mean_gov6[table_stuff$discuss2==2] -5
table_stuff$mean_gov6[table_stuff$discuss2==1] <- table_stuff$mean_gov6[table_stuff$discuss2==1] -10
table_stuff$mean_gov6[table_stuff$mean_gov6>100] <- NA
table(table_stuff$mean_gov6)
table_stuff$mean_gov7[table_stuff$discuss2==2] <- table_stuff$mean_gov7[table_stuff$discuss2==2] -10
table_stuff$mean_gov7[table_stuff$discuss2==1] <- table_stuff$mean_gov7[table_stuff$discuss2==1] -20
table_stuff$mean_gov7[table_stuff$mean_gov7>100] <- NA
table(table_stuff$mean_gov7)
load(qog_url)
qog10 <- subset(qog,qog$year==2000 |
qog$year==2001 |
qog$year==2002 |
qog$year==2003 |
qog$year==2004 |
qog$year==2005 |
qog$year==2006 |
qog$year==2007 |
qog$year==2008 |
qog$year==2009 |
qog$year==2010)
library(countrycode)
qog10$cntry<-countrycode(qog10$ccodecow, "cown","country.name")
qog10$al_ethnic<-as.numeric(qog10$al_ethnic)
#tidyr::gather(qog10,c("cntry","year"),"al_ethnic")
qog10a <- qog10 %>% dplyr::select(cntry,year,al_ethnic) %>%
as.data.frame()
data_wide17 <- reshape(data = qog10a,
idvar = "cntry",
v.names = "al_ethnic",
timevar = "year",
direction = "wide")
#qog10hdi <- qog10 %>% dplyr::select(cntry,year,undp_hdi) %>%
# as.data.frame()
#data_wide_hdi <- hdi
#reshape(data = qog10hdi,
# idvar = "cntry",
# v.names = "undp_hdi",
# timevar = "year",
# direction = "wide")
table(qog$al_ethnic,qog$year)
qog14 <- subset(qog,qog$year==2014)
qog14$cntry<-countrycode(qog14$ccodecow, "cown","country.name")
qog14 <- qog14 %>% dplyr::select(cntry,year,cspf_legit) %>%
as.data.frame()
data_wide18 <- reshape(data = qog14,
idvar = "cntry",
v.names = "cspf_legit",
timevar = "year",
direction = "wide")
qog15 <- subset(qog,qog$year==2015)
qog15$cntry<-countrycode(qog15$ccodecow, "cown","country.name")
qog15 <- qog15 %>% dplyr::select(cntry,year,ffp_sl) %>%
as.data.frame()
data_wide19 <- reshape(data = qog15,
idvar = "cntry",
v.names = "ffp_sl",
timevar = "year",
direction = "wide")
qog10$ciri_physint<-as.numeric(qog10$ciri_physint)
qog10a <- qog10 %>% dplyr::select(cntry,year,ciri_physint) %>%
as.data.frame()
data_wide20 <- reshape(data = qog10a,
idvar = "cntry",
v.names = "ciri_physint",
timevar = "year",
direction = "wide")
qog10$gd_ptss <-as.numeric(qog10$gd_ptss)
qog10a <- qog10 %>% dplyr::select(cntry,year,gd_ptss) %>%
as.data.frame()
data_wide21 <- reshape(data = qog10a,
idvar = "cntry",
v.names = "gd_ptss",
timevar = "year",
direction = "wide")
qog14<-subset(qog,qog$year==2014)
qog13<-subset(qog,qog$year==2013)
qog12<-subset(qog,qog$year==2012)
qog11<-subset(qog,qog$year==2011)
qog10<-subset(qog,qog$year==2010)
qog8<-subset(qog,qog$year==2008)
qog7<-subset(qog,qog$year==2007)
qog6<-subset(qog,qog$year==2006)
qog5<-subset(qog,qog$year==2005)
qog4<-subset(qog,qog$year==2004)
qog3<-subset(qog,qog$year==2003)
qog2<-subset(qog,qog$year==2002)
qog1<-subset(qog,qog$year==2001)
qog0<-subset(qog,qog$year==2000)
table(is.na(qog$wel_culture),qog$year)
culreg<- pmax(qog14$wel_culture, qog13$wel_culture, na.rm = TRUE)
culreg<- pmax(culreg, qog12$wel_culture, na.rm = TRUE)
culreg<- pmax(culreg, qog11$wel_culture, na.rm = TRUE)
culreg<- pmax(culreg, qog10$wel_culture, na.rm = TRUE)
culreg<- pmax(culreg, qog8$wel_culture, na.rm = TRUE)
culreg<- pmax(culreg, qog7$wel_culture, na.rm = TRUE)
culreg<- pmax(culreg, qog6$wel_culture, na.rm = TRUE)
culreg<- pmax(culreg, qog5$wel_culture, na.rm = TRUE)
culreg<- pmax(culreg, qog4$wel_culture, na.rm = TRUE)
culreg<- pmax(culreg, qog3$wel_culture, na.rm = TRUE)
culreg<- pmax(culreg, qog2$wel_culture, na.rm = TRUE)
culreg<- pmax(culreg, qog1$wel_culture, na.rm = TRUE)
culreg<- pmax(culreg, qog0$wel_culture, na.rm = TRUE)
culreg<- as.character(sjmisc::to_label(culreg))
culreg<-as.data.frame(cbind(culreg,qog14$ccodecow))
oreast <- subset(culreg, culreg$culreg == "Orthodox East")
oreast
#culreg<- pmax(culreg, qog10$wel_culture, na.rm = TRUE)
qog14$ht_region
culreg$cntry<-countrycode(culreg$V2, "cown","country.name")
tabeletto<-merge(table_stuff,culreg,by="cntry")
tabeletto<-as.data.frame(cbind(table_stuff$regions,
as.character(table_stuff$cntry),
as.character(tabeletto$culreg)))
tabeletto <- tabeletto[order(tabeletto$V1, tabeletto$V3),]
#edit(tabeletto)
culreg<-data.frame(cbind(tabeletto,culreg))
culreg<-culreg[,c(2,4)]
names(culreg)[1]<-c("cntry")
table_stuff3 <- merge(table_stuff,culreg,by="cntry")
table(as.character(tabeletto$V3))
qog100 <- subset(qog,qog$year==2010)
qog100$cntry<-countrycode(sjmisc::to_label(qog100$ccodecow), "cown","country.name")
qog100 <- qog100 %>% dplyr::select(cntry,year,ht_regtype1) %>%
as.data.frame()
qog100$regtype<-sjmisc::to_label(qog100$ht_regtype1)
qog100$year <- NULL
qog100$ht_regtype1 <- NULL
table(qog100$regtype)
ethnic10<-as.numeric(rowMeans(data_wide17[,2:12])) # mean over last 10 years (2000 - 2010)
physint10<-as.numeric(rowMeans(data_wide20[,2:12])) # mean over last 10 years (2000 - 2010)
terror10<-as.numeric(rowMeans(data_wide21[,2:12])) # mean over last 10 years (2000 - 2010)
legit<-as.numeric(data_wide18[,2]) # mean over last 10 years (2000 - 2010)
legit2<-as.numeric(data_wide19[,2]) # mean over last 10 years (2000 - 2010)
qogthingy<-data.frame(data_wide19[,1],ethnic10,legit,legit2,physint10,terror10)
colnames(qogthingy)[1]<-c("cntry")
qogthingy<-merge(x=qogthingy, y=qog100, by="cntry")
#qogthingy<-data.frame(data_wide17[,1],ethnic10)
#colnames(qogthingy)[1]<-c("cntry")
#combined <- merge(x=qogthingy, y=combined, by="cntry")
qog_cs <-read_spss("C:/Users/Favone/Downloads/qog_std_cs_jan17.sav") #loading dataset
qog_cs$cntry<-countrycode(qog_cs$ccodecow, "cown","country.name")
qog_cs$legit3<-as.numeric(qog_cs$gov_ixlegitimacyindex)
legit_dat<-data.frame(qog_cs$cntry,qog_cs$legit3)
colnames(legit_dat)<-c("cntry","legit3")
aggrdelib <- merge(x=legit_dat, y=aggrdelib, by="cntry")
aggrdelib$legit3 <- range01(aggrdelib$legit3)
cor(na.omit(aggrdelib[,c(4,5,7,13)]))
cor(na.omit(aggrdelib[,c(4,5,2,6:13)]))
aggrdelib$legit <- 1-range01(aggrdelib$legit)
aggrdelib$legit2 <- 1-range01(aggrdelib$legit2)
aggrdelib$asia <- aggrdelib$e.asia + aggrdelib$s.e.asia + aggrdelib$s.asia + aggrdelib$pacific
SFI <-read_spss("C:/Users/Favone/Downloads/SFIv2016.sav") #loading dataset
SFI <- subset(SFI,SFI$year==2015)
SFI$cntry <-countrycode(SFI$country, "country.name","country.name")
SFI$cntry[79] <- "North Korea"
SFI$cntry <-countrycode(SFI$cntry, "country.name","country.name")
SFI$legitimacy <- SFI$legit
SFI$legit <- NULL
aggrdelib <- merge(x=SFI, y=aggrdelib, by="cntry")
hdi <- read_csv("hdi.csv")
hdi$cntry<-countrycode(hdi$Country, "country.name","country.name")
hdi$'1990'<- NULL ; hdi$'1991'<- NULL ; hdi$'1992'<- NULL ; hdi$'1993'<- NULL
hdi$'1994'<- NULL; hdi$'1995'<- NULL; hdi$'1996'<- NULL; hdi$'1997'<- NULL
hdi$'1998'<- NULL ; hdi$'1999'<- NULL ; hdi$'2011'<- NULL ; hdi$'2012'<- NULL
hdi$'2013'<- NULL; hdi$'2014'<- NULL; hdi$'2015'<- NULL;hdi$`HDI Rank (2015)`<- NULL
hdi$Country<- NULL
hdi10<-as.numeric(rowMeans(hdi[,1:11]))
hdat<-data.frame(hdi$cntry,hdi10)
names(hdat)<-c("cntry","hdi10")
aggrdelib <- merge(x=hdat, y=aggrdelib, by="cntry")
#table(aggrdelib$hdi10)
#gc()
#combined <- merge(x=hdat, y=combined, by="cntry")
#colnames(aggrdelib)[9]<-"e_p_polity"
#lop<-subset(vdems_start,vdems_start$year==2010)
cor(na.omit(aggrdelib2[,2:17]))
cor(na.omit(data.frame(aggrdelib$polity10,aggrdelib$delib10)))
#hist(vdems$v2dlconslt)
#hist(vdems$v2xcl_disc)
#table(vdems_start$e_boix_regime,vdems_start$year)
#table(vdems_sub$e_p_polity,vdems_sub$year)
##### merging time ####
combined <- merge(x=merged, y=aggrdelib, by="cntry")
table(combined$cntry)
combined <- as.data.frame(combined)
combined$gov_trust <- as.numeric(combined$gov_trust)
combined$age <- as.numeric(combined$age)
combined$income <- as.numeric(combined$income)
combined$educ <- as.numeric(combined$educ)
combined$sex <- as.factor(combined$sex)
combined$authoritarian <- as.numeric(combined$authoritarian)
combined$safety <- as.numeric(combined$safety)
# combined$demtoday <- as.numeric(combined$demtoday)
combined$latino <- factor(combined$latino)
combined$afro <- factor(combined$afro)
combined$americas <- factor(combined$americas)
combined$asia <- combined$e.asia + combined$s.e.asia + combined$s.asia + combined$pacific
cor(na.omit(data.frame(combined$gov_trust,combined$income,combined$educ, #Socioeconomic factors
combined$delib10, combined$polity10, combined$gdp10)))
combined$cntry<-as.factor(combined$cntry)
#combined$polity10 <- combined$polity10*20-10
#combined$regime <- combined$polity10
#combined$regime[combined$polity_autodummy==1] <- "auto"
#combined$regime[combined$polity_anodummy==1] <- "ano"
#combined$regime[combined$polity_demdummy==1] <- "demo"
hist(combined$gov_trust)
qplot(combined$gov_trust)
combined$cntry
#physi_s <- vdems_sub2 %>% dplyr::select(cntryears, franz)
#combined <- merge(combined, physi_s, by = "cntryears")
#physi2_s <- ddply(combined,~cntry,
# summarise,politcat=mean(franz,na.rm=T))
#combined <- merge(combined, physi2_s, by = "cntry")
vdems_sub2$cntryears <- paste(vdems_sub2$cntry,vdems_sub2$year)
physi <- vdems_sub2 %>% dplyr::select(cntryears, perc)
combined <- merge(combined, physi, by = "cntryears")
physi2 <- ddply(combined,~cntry,
summarise,physviol=mean(perc,na.rm=T))
combined <- merge(combined, physi2, by = "cntry")
#physi_22$dis3 <-round(physi_22$dis2)
#unique(physi2_s$cntry)
#1-2.5
#3-5
#5.5 - 7
#physi2_s$politcat2<-8-((physi2_s$politcat) * (7/10))
#11
#physi2_s$polity_demdummy <- physi2_s$politcat2
#physi2_s$polity_demdummy [physi2_s$politcat2 <= 2.5] <- 1
#physi2_s$polity_demdummy [physi2_s$politcat2 > 2.5] <- 0
#table(physi2_s$polity_demdummy)
#physi2_s$polity_anodummy <- physi2_s$politcat2
#physi2_s$polity_anodummy[physi2_s$politcat2 > 2.5 & physi2_s$politcat2 < 5.5] <- 1
#physi2_s$polity_anodummy[physi2_s$politcat2 <= 2.5 | physi2_s$politcat2 >= 5.5] <- 0
#table(physi2_s$polity_anodummy)
#physi2_s$polity_autodummy <- physi2_s$politcat2
#physi2_s$polity_autodummy[physi2_s$politcat2 >= 5.5] <- 1
#physi2_s$polity_autodummy[physi2_s$politcat2 < 5.5] <- 0
#table(physi2_s$polity_autodummy)
#physi2_s$regime <- physi2_s$politcat
#physi2_s$regime[physi2_s$polity_autodummy==1] <- "auto"
#physi2_s$regime[physi2_s$polity_anodummy==1] <- "ano"
#physi2_s$regime[physi2_s$polity_demdummy==1] <- "demo"
#unique(physi2_s$cntry)
table(physi2_s$regime)
qog2000 <- subset(qog,qog$year==2010 |
qog$year==2011 |
qog$year==2012 |
qog$year==2013 |
qog$year==2014 |
qog$year==2015)
table(qog2000$gd_ptsa,qog2000$year)
qog2000$perc2 <- qog2000$gd_ptsa
qog2000$cntry<-countrycode(qog2000$ccodecow, "cown","country.name")
qog2000$cntryears <- paste(qog2000$cntry,qog2000$year)
physi2000 <- qog2000 %>% dplyr::select(cntryears, perc2)
combined <- merge(combined, physi2000, by = "cntryears")
physi22000 <- ddply(combined,~cntry,
summarise,terror=mean(perc2,na.rm=T))
combined <- merge(combined, physi22000, by = "cntry")
#table(qog2000$undp_hdi,qog2000$year)
#physiff <- qog2000 %>% dplyr::select(cntryears, undp_hdi)
#combined <- merge(combined, physiff, by = "cntryears")
#physiff2 <- ddply(combined,~cntry,
# summarise,hdi=mean(undp_hdi,na.rm=T))
#combined <- merge(combined, physiff2, by = "cntry")
gni <- read_csv("GNI.csv", skip = 1)
gni$`2015`<-gsub("ttt","",gni$`2015`)
gni$`2015`<-gsub("ff","",gni$`2015`)
gni$`2015`<-gsub("sss","",gni$`2015`)
gni$`2015`<-gsub("uuu","",gni$`2015`)
gni$`2015`<-gsub("o","",gni$`2015`)
gni$`2015` <- as.numeric(gni$`2015`)
gni$`2014`<-gsub("ttt","",gni$`2014`)
gni$`2014`<-gsub("ff","",gni$`2014`)
gni$`2014`<-gsub("sss","",gni$`2014`)
gni$`2014`<-gsub("uuu","",gni$`2014`)
gni$`2014`<-gsub("o","",gni$`2014`)
gni$`2014` <- as.numeric(gni$`2014`)
gni<-gni[,c(2,23:28)]
gni<-gather(as.data.frame(gni),key = "Country")
names(gni) <- c("cntry","year","gni")
gni$cntry<-countrycode(gni$cntry,"country.name","country.name")
gni$cntryears <- paste(gni$cntry,gni$year)
physigni <- gni %>% dplyr::select(cntryears, gni)
combined <- merge(combined, physigni, by = "cntryears")
physigni2 <- ddply(combined,~cntry,
summarise,gni_c=mean(gni,na.rm=T))
combined <- merge(combined, physigni2, by = "cntry")
mutate(regions = vdems_sub %>%
dcast(country_name ~ year,
value.var=c("e_regionpol")) %>%
select('2000') %>%
mutate(regions = fct_recode(as.factor(`2000`),
"E. Europe and C. Asia (post-Communist)" = "1",
"Latin America & Carribean" = "2",
"MENA" = "3",
"Sub-Saharan Africa" = "4",
"W. Europe and N. America" = "5",
"South & East Asia & Pacific" = "6",
"South & East Asia & Pacific" = "7",
"South & East Asia & Pacific" = "8",
"South & East Asia & Pacific" = "9",
"Latin America & Carribean" = "10") %>%
as_factor)) %>%
select(regions)
table(regions)
regions2 <- vdems_sub %>%
dcast(country_name ~ year,
value.var=c("e_regionpol")) %>%
select('2000') %>%
transmute(fct_recode(as.factor(`2000`),
"E. Europe and C. Asia (post-Communist)" = "1",
"Latin America & Carribean" = "2",
"MENA" = "3",
"Sub-Saharan Africa" = "4",
"W. Europe and N. America" = "5",
"East Asia" = "6",
"South-East Asia" = "7",
"South Asia" = "8",
"Pacific" = "9",
"Latin America & Carribean" = "10"))
table(regions2)
regions3 <- dcast(vdems_sub, country_name ~ year, value.var=c("e_regionpol"))$"2000"
postcom <- as.numeric(regions3 == 1)
latin <- as.numeric(regions3 == 2 | regions3 == 10)
mena <- as.numeric(regions3 == 3)
subsahara <- as.numeric(regions3 == 4)
west <- as.numeric(regions3 == 5)
e.asia <- as.numeric(regions3 == 6)
s.e.asia <- as.numeric(regions3 == 7)
s.asia <- as.numeric(regions3 == 8)
pacific <- as.numeric(regions3 == 9)
ww <- vdems_sub %>%
dcast(country_name ~ year,
value.var=c("e_regionpol")) %>%
select('2000') %>%
mutate(regions = fct_recode(as.factor(`2000`),
"E. Europe and C. Asia (post-Communist)" = "1",
"Latin America & Carribean" = "2",
"MENA" = "3",
"Sub-Saharan Africa" = "4",
"W. Europe and N. America" = "5",
"South & East Asia & Pacific" = "6",
"South & East Asia & Pacific" = "7",
"South & East Asia & Pacific" = "8",
"South & East Asia & Pacific" = "9",
"Latin America & Carribean" = "10")) %>%
as_factor() %>%
select(regions)
ww
regions2 <- vdems_sub %>%
dcast(country_name ~ year,
value.var=c("e_regionpol")) %>%
select('2000') %>%
transmute(fct_recode(as.factor(`2000`),
"E. Europe and C. Asia (post-Communist)" = "1",
"Latin America & Carribean" = "2",
"MENA" = "3",
"Sub-Saharan Africa" = "4",
"W. Europe and N. America" = "5",
"East Asia" = "6",
"South-East Asia" = "7",
"South Asia" = "8",
"Pacific" = "9",
"Latin America & Carribean" = "10"))
table(regions2)
regions3 <- dcast(vdems_sub, country_name ~ year, value.var=c("e_regionpol"))$"2000"
postcom <- as.numeric(regions3 == 1)
latin <- as.numeric(regions3 == 2 | regions3 == 10)
mena <- as.numeric(regions3 == 3)
subsahara <- as.numeric(regions3 == 4)
west <- as.numeric(regions3 == 5)
e.asia <- as.numeric(regions3 == 6)
s.e.asia <- as.numeric(regions3 == 7)
s.asia <- as.numeric(regions3 == 8)
pacific <- as.numeric(regions3 == 9)